package com.wits.qso.entity;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.springframework.format.annotation.DateTimeFormat;

import com.wits.platform.entity.BaseEntity;

/**
 * 课程注册实体类
 * 
 */
@Entity
@Table(name = "qso_course_register")
public class CourseRegister extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6446278314762692600L;

	/** 课程注册申请单编号 **/
	private String id;

	// /** 学生编号 **/
	// private String stuId;
	//
	// /**
	// * 学生名称
	// */
	// @Transient
	// private String stuName;

	/**
	 * 学生
	 */
	private Student student;
	/**
	 * 课程
	 */
	private Course course;

	/**
	 * 教师
	 */
	private Teacher teacher;
	//
	// /** 课程编号 **/
	// private String courseId;
	//
	// /**
	// * 课程名称
	// */
	// @Transient
	// private String courseName;

	// /** 老师编号 **/
	// private String terId;
	//
	// /**
	// * 老师名称
	// */
	// @Transient
	// private String terName;

	/**
	 * 申请状态
	 */
	private String crStatus;

	/**
	 * 申请说明
	 */
	private String crMessage;

	/** 申请日期 **/
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date applyDate;

	/** 批准日期 **/
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date authDate;

	@Id
	@GenericGenerator(name = "idGen", strategy = "com.wits.platform.common.id.generator.IDGenerator", parameters = {
			@Parameter(name = "segment_value", value = "QSO_CR_ID"),
			@Parameter(name = "table_name", value = "wits_id_generator"),
			@Parameter(name = "value_column_name", value = "gen_value"),
			@Parameter(name = "segment_column_name", value = "gen_name"),
			@Parameter(name = "segment_value_length", value = "10"),
			@Parameter(name = "sq_format", value = "%08d"),
			@Parameter(name = "sq_prefix", value = "RC") })
	@GeneratedValue(generator = "idGen")
	@Column(name = "cr_id", nullable = false, insertable = true, updatable = false, length = 10)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne
	@JoinColumn(name = "stu_id", updatable = true)
	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}

	// @Column(name = "stu_id")
	// public String getStuId() {
	// return stuId;
	// }
	//
	// public void setStuId(String stuId) {
	// this.stuId = stuId;
	// }

	@ManyToOne
	@JoinColumn(name = "course_id", updatable = true)
	public Course getCourse() {
		return course;
	}

	public void setCourse(Course course) {
		this.course = course;
	}

	// @Column(name = "course_id")
	// public String getCourseId() {
	// return courseId;
	// }
	//

	// public void setCourseId(String courseId) {
	// this.courseId = courseId;
	// }

	@ManyToOne
	@JoinColumn(name = "ter_id", updatable = true)
	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	// @Column(name = "ter_id")
	// public String getTerId() {
	// return terId;
	// }
	//
	// public void setTerId(String terId) {
	// this.terId = terId;
	// }

	@Column(name = "cr_status", length = 2)
	public String getCrStatus() {
		return crStatus;
	}

	public void setCrStatus(String crStatus) {
		this.crStatus = crStatus;
	}

	@Column(name = "cr_message", length = 200)
	public String getCrMessage() {
		return crMessage;
	}

	public void setCrMessage(String crMessage) {
		this.crMessage = crMessage;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date_apply")
	public Date getApplyDate() {
		return applyDate;
	}

	public void setApplyDate(Date applyDate) {
		this.applyDate = applyDate;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date_auth")
	public Date getAuthDate() {
		return authDate;
	}

	public void setAuthDate(Date authDate) {
		this.authDate = authDate;
	}

	// @Column(name = "stu_name")
	// public String getStuName() {
	// return stuName;
	// }
	//
	// public void setStuName(String stuName) {
	// this.stuName = stuName;
	// }
	//
	// @Column(name = "course_title")
	// public String getCourseName() {
	// return courseName;
	// }
	//
	// public void setCourseName(String courseName) {
	// this.courseName = courseName;
	// }

	// @Column(name = "ter_name")
	// public String getTerName() {
	// return terName;
	// }
	//
	// public void setTerName(String terName) {
	// this.terName = terName;
	// }

	// public String toString() {
	// return JSONObject.fromObject(this, CourseRegister.getBaseJsonConfig())
	// .toString();
	// }

	public String toString() {
		StringBuffer buf = new StringBuffer();
		buf.append("{ ");
		buf.append("\"id\":\"").append(this.id);
		buf.append("\",\"terId\":\"").append(this.teacher.getTerId());
		buf.append("\",\"terName\":\"").append(this.teacher.getTerName());
		buf.append("\",\"stuId\":\"").append(this.student.getStuId());
		buf.append("\",\"stuName\":\"").append(this.student.getStuName());
		buf.append("\",\"courseId\":\"").append(this.course.getId());
		buf.append("\",\"courseName\":\"").append(this.course.getTitle());
		buf.append("\",\"applyDate\":\"").append(this.applyDate);
		buf.append("\",\"authDate\":\"").append(this.authDate);
		buf.append("\",\"crStatus\":\"").append(this.crStatus);
		buf.append("\",\"crMessage\":\"").append(this.crMessage);
		buf.append("\" }");
		return buf.toString();
	}

	public String display() {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 返回表字段集合
	 * 
	 * @return
	 */
	public static Map<String, String> getTableColumnNames() {
		Map<String, String> res = new HashMap<String, String>();
		res.put("cr_id", "=");
		res.put("stu_id", "=");
		res.put("ter_id", "=");
		res.put("course_id", "=");
		res.put("cr_status", "=");
		res.put("cr_message", "like");
		res.put("date_apply", "=");
		res.put("date_auth", "=");
		res.put("remark", "like");
		res.put("user_cre", "like");
		res.put("date_cre", "=");
		res.put("user_upd", "like");
		res.put("date_upd", "=");
		return res;
	}
}
